package com.zucc.controller;

import com.zucc.controller.req.ResourceAddReq;
import com.zucc.controller.req.ResourceModifyReq;
import com.zucc.controller.req.ResourceSearchReq;
import com.zucc.controller.resp.ResourceResp;
import com.zucc.service.ResourceService;
import com.zucc.service.base.PageData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author : charspan
 * @Description :
 * @create : 2021-12-11 8:53 下午
 */
@RestController
@Slf4j
@RequestMapping("/v1/api/resources")
@Api(tags = "资源管理")
public class ResourceController {
    @Resource
    private ResourceService resourceService;

    @ApiOperation(value = "新增资源")
    @PostMapping
    void add(@RequestBody @Validated ResourceAddReq req) {
        resourceService.add(req);
    }

    @ApiOperation(value = "修改资源")
    @PutMapping
    void modify(@RequestBody @Validated ResourceModifyReq req) {
        resourceService.modify(req);
    }

    @ApiOperation(value = "删除资源")
    @ApiImplicitParam(paramType = "path", name = "id", value = "资源编号", dataType = "Long", example = "1", required = true)
    @DeleteMapping("/{id}")
    void deleteOne(@PathVariable Long id) {
        resourceService.deleteOne(id);
    }

    @ApiOperation(value = "资源分页")
    @PostMapping("/page")
    PageData<ResourceResp> page(@RequestBody @Validated ResourceSearchReq req) {
        return resourceService.page(req);
    }
}
